﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using GMap.NET;

namespace MyPoints
{
  public  static class XmlBo
  {
    public static T  LoadXml <T>(string fileName)
    {
      T ret;
      XmlSerializer ser = new XmlSerializer(typeof(T));


      using (System.IO.FileStream fl =
        new System.IO.FileStream(fileName, System.IO.FileMode.Open))
      {
        ret = (T)ser.Deserialize(fl);
      }

      return ret;
    } 
    
    public static void SaveXml <T>(T dataObject, string fileName)
    {
      XmlSerializer ser = new XmlSerializer(typeof(T));
      string tmpFileName = System.IO.Path.GetTempFileName();

      using (System.IO.FileStream fl =
        new System.IO.FileStream(tmpFileName, System.IO.FileMode.Truncate))
      {
        ser.Serialize(fl, dataObject);
      }

      System.IO.File.Copy(tmpFileName, fileName, true);
      System.IO.File.Delete(tmpFileName);
    } 
  }
}
